package com.html;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;

import com.model.xmlElement.DataColumn;
import com.tool.StringUtil;

import constant.HtmlConstant;
/**
 * *********************************************
 * @author Administrator
 * @FileName ParseTagNodeArray.java
 * @Description解析org.w3c.dom.Node[](不带pattern)
 **********************************************
 */
public class ParseW3CNodeArrayNoPattern extends ParseW3CNodeArray{
	public static final Logger LOG = LoggerFactory.getLogger(ParseW3CNodeArrayNoPattern.class);
	
	private ParseHtml parseHtml;
	private DataColumn dataColumn;
	private Node[] nodes;
	
	public ParseHtml getParseHtml() {
		return parseHtml;
	}
	public void setParseHtml(ParseHtml parseHtml) {
		this.parseHtml = parseHtml;
	}
	public DataColumn getDataColumn() {
		return dataColumn;
	}
	public void setDataColumn(DataColumn dataColumn) {
		this.dataColumn = dataColumn;
	}
	public Node[] getNodes() {
		return nodes;
	}
	public void setNodes(Node[] nodes) {
		this.nodes = nodes;
	}
	public ParseW3CNodeArrayNoPattern(){}
	public ParseW3CNodeArrayNoPattern(ParseHtml parseHtml, DataColumn dataColumn, Node[] nodes) {
		super();
		this.parseHtml = parseHtml;
		this.dataColumn = dataColumn;
		this.nodes = nodes;
	}
	
	
	public String parse(){
		String outPutType = dataColumn.getDataColumnOutput().getOutputType();
		StringBuilder stringBuilder = new StringBuilder(100);
		Node node;
		for(int i = 0,length = nodes.length;i < length;i++){
			node = nodes[i];
			if(outPutType.equals(HtmlConstant.OUTPUTTYPE_TEXT)){
				stringBuilder.append(node.getTextContent().toString());
			}else if(outPutType.equals(HtmlConstant.OUTPUTTYPE_HTML)){
				stringBuilder.append(ParseImgs.parse(parseHtml.getSeed(), nodeToHtml(node)));
			}
		}
		String tagNodeValue = StringUtil.parseContent(stringBuilder.toString());
		if(tagNodeValue != null && !"".equals(tagNodeValue)){
			tagNodeValue = tagNodeValue.replace("\"", "'");
		}
		return tagNodeValue;
	}

}
